// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CDateTime.
//   $Id$
// DateTime.h: interface for the CDateTime class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DATETIME_H__ADDA8BF9_B280_4EB2_A2F1_FADAA2BDDBE0__INCLUDED_)
#define AFX_DATETIME_H__ADDA8BF9_B280_4EB2_A2F1_FADAA2BDDBE0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CDateTime  
{
public:
	static HRESULT from_ISO8601E(BSTR sDuration, SYSTEMTIME * pst, bool * pbNegative);
	static HRESULT from_ISO8601(BSTR sTime,SYSTEMTIME * tResult);
	static HRESULT to_ISO8601(SYSTEMTIME t, BSTR * psResult);
	CDateTime();
	virtual ~CDateTime();

private:	
	static HRESULT getNumber(CString& sSource, int iStart, int iLength, unsigned short & lTarget);
	inline static void numberToZeroFilledString(long number,unsigned long lSize,BSTR * psRetVal)
	{
		//used to create numeric strings of required length by prepending zeros
		//	eg: 1 = 001

		char pcBuf[11]; //long can make a 10 digit string plus a potential sign.
		_ltoa(number,pcBuf,10);
		CComBSTR sBuf(pcBuf);

		CComBSTR sBuf2;
		while(sBuf.Length() < lSize) 
		{
			sBuf2 = "0";
			sBuf2 += sBuf;
			sBuf = sBuf2.m_str;
		}
		*psRetVal = sBuf.Detach();
	}
};

#endif // !defined(AFX_DATETIME_H__ADDA8BF9_B280_4EB2_A2F1_FADAA2BDDBE0__INCLUDED_)
